<?php
/**************************************************************************************************
|
| AudioShare - Audio Sharing Script
| http://www.audiosharescript.com
| webmaster@audiosharescript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.audiosharescript.com/eula.html and to be bound by it.
|
| Copyright (c) 2010 AudioShareScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
STemplate::assign('issignuppage',"1");
$redirect = base64_decode($_REQUEST['redirect']);
$redirect = escape($redirect);

include_once('fbk-sdk/facebook.php');
date_default_timezone_set('America/Los_Angeles');
/*$facebook = new Facebook(array(
  'appId'  => "306359929425066",
  'secret' => "7b7ecc00b68b89b5024dd64fa55bef11",
));*/

/*$facebook = new Facebook(array(
  'appId'  => "244234112337589",
  'secret' => "51d66c487729e5e767b585bcf8f63537",
));*/
   
 $facebook = new Facebook(array(
  'appId'  => "188710037898545",
  'secret' => "68404a0a62afeac2f20423517ddb9460",
));


// Get User ID
$user = $facebook->getUser();

if ($user) {
	try {
        $access_token = $facebook->getAccessToken();
		$user_profile = $facebook->api('/me');
		
	} catch (FacebookApiException $e) {
		error_log($e);
		$user = null;
	}
}//end if
if ($user) {
	$logoutUrl = $facebook->getLogoutUrl();
	$_SESSION[LOGOUT] = $logoutUrl;
} else {
	$loginUrl = $facebook->getLoginUrl(array('scope' => 'user_events'));
}//end if

if($user) {
	$_SESSION[USERID]=$user_profile["id"];
	$_SESSION[EMAIL]="";
	$_SESSION[USERNAME]=$user_profile["name"];
	$_SESSION[VERIFIED]="";
	$_SESSION[FACEBOOK]="1";
	
	if($redirect == "")
	{
		header("Location:$config[baseurl]");exit;
	}
	else
	{
		header("Location:$redirect");exit;
	}
}
?>
<form method="post" action="<?php echo $loginUrl;?>" name="frmFbkLogin"></form>
<script>document.frmFbkLogin.submit();</script>